package com.lancoo.znbkxx.teacher.ui.dialog

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.text.Html
import android.view.Gravity
import android.view.ViewGroup
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.aibkTestCoach.networkRequest.entity.ClassStuLanguageAbilityInfor
import com.lancoo.znbkxx.teacher.ui.adapter.AibkLanguageAbailityStuItemAdapter
import kotlinx.android.synthetic.main.aibk_dialog_estimate_grade_student_interval_list.IvCloseDialog
import kotlinx.android.synthetic.main.aibk_dialog_estimate_grade_student_interval_list.TvTitleStuIntervalList
import kotlinx.android.synthetic.main.aibk_dialog_student_language_diagnosis_abaility_list.*

class DialogLanguageDiagnosisAbailityList(
        context: Context?,
        val classStuLanguageAbilityInfor: ClassStuLanguageAbilityInfor
) : Dialog(context!!, R.style.CustomDialog) {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.aibk_dialog_student_language_diagnosis_abaility_list)
        window!!.setGravity(Gravity.BOTTOM) //设置弹窗右对齐
        window!!.setWindowAnimations(R.style.MyDialogBottomTranslate) //设置动画效果

        val wl = window!!.attributes
        //以下这两句是为了保证按钮可以水平满屏
        wl.width = ViewGroup.LayoutParams.MATCH_PARENT;
        wl.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        onWindowAttributesChanged(wl)
        setCanceledOnTouchOutside(true)

        //初始化界面数据
        initView()
    }

    /**
     * 初始化界面控件的显示数据
     */
    private fun initView() {

        //关闭dialog
        IvCloseDialog.setOnClickListener {
            dismiss()
        }

        //显示大标题内容
        var ablilityNameString = ""
        val ablilityName = classStuLanguageAbilityInfor.ClassAbilityInfo[0].AblilityName
        if (ablilityName == "TL") {
            ablilityNameString = "听力"
        } else if (ablilityName == "KY") {
            ablilityNameString = "口语"
        } else if (ablilityName == "YD") {
            ablilityNameString = "阅读"
        } else if (ablilityName == "XZ") {
            ablilityNameString = "写作"
        }
        TvTitleStuIntervalList.text = "语言认知能力情况 · " + ablilityNameString + "能力"

        //显示能力较好
        val totalNumGood = classStuLanguageAbilityInfor.ClassAbilityInfo[0].AbilityInfo[0].TotalNum
        TvAbailityGood.text = Html.fromHtml(context.resources.getString(R.string.aibk_class_student_language_abaility_infor,
                        ablilityNameString, "较好", totalNumGood))
        //显示能力一般
        val totalNumGeneral = classStuLanguageAbilityInfor.ClassAbilityInfo[0].AbilityInfo[1].TotalNum
        TvAbailityGeneral.text = Html.fromHtml(context.resources.getString(R.string.aibk_class_student_language_abaility_infor,
                        ablilityNameString, "一般", totalNumGeneral))

        //显示能力较差
        val totalNumBad = classStuLanguageAbilityInfor.ClassAbilityInfo[0].AbilityInfo[2].TotalNum
        TvAbailityBad.text = Html.fromHtml(context.resources.getString(R.string.aibk_class_student_language_abaility_infor,
                        ablilityNameString, "较差", totalNumBad))


        RvStuAbailityGoodList.layoutManager = StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)
        val mAdapter0 = AibkLanguageAbailityStuItemAdapter(context, classStuLanguageAbilityInfor, 0)
        RvStuAbailityGoodList.adapter = mAdapter0

        RvStuAbailityGeneralList.layoutManager = StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)
        val mAdapter1 = AibkLanguageAbailityStuItemAdapter(context, classStuLanguageAbilityInfor, 1)
        RvStuAbailityGeneralList.adapter = mAdapter1

        RvStuAbailityBadList.layoutManager = StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)
        val mAdapter2 = AibkLanguageAbailityStuItemAdapter(context, classStuLanguageAbilityInfor, 2)
        RvStuAbailityBadList.adapter = mAdapter2

    }

}